<template>
	<view>
		<u-cell-group>
			<u-cell v-for="(item, index) in venueInfoList" :key="index" @click="venueLoginSubmit(item.t, item.d)"
			:icon="item.img" 
			:title="item.venueName" 
			:iconStyle="{width: '120rpx', height: '120rpx'}"
			isLink
			>
			
			<view
			    	    slot="label"
			    	    class="u-slot-label" style="color: #909193;letter-spacing: 0.7px; font-size: 28rpx; display: -webkit-box;
	text-overflow: ellipsis;
	overflow: hidden;
	-webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;"
			    	>{{ item.address }}</view>
			
			</u-cell>
		</u-cell-group>
		<view style="padding: 30rpx;text-align: center;">
			<text style="color: #909193;font-size: 30rpx;" @click="outMerchant">退出商家</text>
		</view>
	</view>
</template>

<script>
	import utils from '@/utils/utils.js';
	export default {
		data() {
			return {
				//场馆列表
				venueInfoList: []
			}
		},
		onLoad() {
			this.initData();
		},
		methods: {
			initData(){
				let baseUrl = 'https://www.gxjuxinxiang.com/api';
				var header = {};
				header.Authorization = 'Basic c2FiZXI6c2FiZXJfc2VjcmV0';
				header['Tenant-Id'] = '000000';
				const token = uni.getStorageSync("venueToken");
				const tokenType = uni.getStorageSync("venueTokenType");
				if (token) {
					header['Blade-Auth'] = `${tokenType} ${token}`;
				}
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				uni.request({
					url: baseUrl + '/blade-merchant-app/merchant-app/user/getUser',
					method: 'GET',
					data: {},
					dataType: 'JSON',
					header: header,
					timeout: 50000,
					success: res => {
						const result = res.data;//JSON.parse(res.data); 如果为小程序需要使用到parse
						uni.hideLoading();
						if (res.statusCode === 200) {
							this.venueInfoList = result.data.venueInfoList;
						} else if (res.statusCode === 401) {
							utils.onLogout();
						}
					},
					fail: error => {
						uni.hideLoading();
						uni.showToast({
							icon: 'error',
							title: '网络信号差',
							mask: true,
							duration: 2000
						});
					}
				})
				
			},
			//切换场馆登录
			venueLoginSubmit(username, password){
				uni.showLoading({
					title: '稍等中',
					mask: true
				})
				this.$request({
					url: `/blade-auth/oauth/token?tenantId=000000&username=${username}&password=${password}&grant_type=password&scope=all&type=account`,
					type: 'POST'
				}).then(res => {
					uni.hideLoading();
					uni.setStorageSync('avatar', res.avatar);
					uni.setStorageSync('account', res.account);
					uni.setStorageSync('nickName', res.nick_name);
					uni.setStorageSync('token', res.access_token);
					uni.setStorageSync('tokenType', res.token_type);
					uni.setStorageSync('userId', res.user_id);
					//身份（1：普通用户，2：场馆主，3：教练员，4：指导员，5：体检中心,7场馆主商家）
					uni.setStorageSync('identity', res.identity);
					var venueIdentity = uni.getStorageSync('venueIdentity');
					console.log("venueIdenwwwtity",venueIdentity);
					uni.redirectTo({ url:'/pages/index/index' })
				})
			},
			//商家端退出
			outMerchant(){
				uni.removeStorageSync("venueToken");
				uni.removeStorageSync("venueTokenType");
				utils.onLogout();
			}
			
		}
	}
</script>

<style>

</style>